<?php

 /**
 * Timetable controller
 *
 * Timetable controller in application
 *
 * PHP Version: 1.2.3
 *
 * @author Johari <joharijumali@gmail.com>
 */

/**
 * Admin Time Table class
 *
 * Admin Time Table class
 *
 * @author Johari <joharijumali@gmail.com>
 */

class Administrator_Timetable_Controller extends Base_Controller
{

    public $restful = true;
	
	/**
     * Working Group function
	 * Component : groupSchedule
	 * Method 	 : ajax post
	 *
	 * @return void.
     */
    public function get_groupSchedule()
    {
        $data['groupList'] = Data_Attendance_Group::listGroup();
        
        return View::make('administrator.timetable.groupschedule', $data);
    }

	/**
     * Function post_addGroup
	 *
	 * @return post_addGroup.
     */
    public function post_addGroup()
    {
        $input = Input::all();
		
		$rules = array(
            'wjkp_no_kumpulan' => 'required|unique:sys_user_kumpulan_pekerja,sukp_no_kumpulan',
        );
        
        $messages = array(
            'unique' => 'No. Kumpulan Telah Wujud',
        );
        
        $validation = Validator::make($input, $rules, $messages);

        if ($validation->fails()) {
            return json_encode($validation->errors);
        }

        if ($input['wjkp_no_auto'] == null) {
            $groupID = Data_Attendance_Group::addGetId($input);
        } else {
            Data_Attendance_Group::updateGroup($input);
            $groupID = $input['wjkp_no_auto'];
        }

        return json_encode(Data_Attendance_Group::listGroup());
    }
	
	public function post_editGroupData()
	{
        $input = Input::all();
				
		$rules = array(
            'wjkp_no_kumpulan' => 'required|unique:sys_user_kumpulan_pekerja,sukp_no_kumpulan,'.$input['wjkp_no_auto'].',sukp_no_auto',
        );
        
        $messages = array(
            'unique' => 'No. Kumpulan Telah Wujud',
        );
        
        $validation = Validator::make($input, $rules, $messages);

		if ($validation->fails()) {
			return json_encode($validation->errors);
		}
														
		Data_Attendance_Group::updateGroup($input);
				
        return json_encode(Data_Attendance_Group::listGroup());
    }
	
	/**
     * Function get_groupInfo
	 *
	 * @return get_groupInfo.
     */
    public function get_groupInfo()
    {
        $groupInfo = Data_Attendance_Group::groupInfo(Input::get('id'));

        return json_encode($groupInfo);
    }
	
	public function post_deleteGroup()
    {
		$input = Input::get();
		$id = Input::get('id');
		
		$bil = Console_Profile::where('sukp_no_auto', '=', $id)->count();

        if($bil == 0):
            Data_Attendance_Group::deleteGroup($input);
            return json_encode(Data_Attendance_Group::listGroup());
        else:
            return json_encode(array('fail'=>'Kumpulan Ini Sedang Digunakan Oleh Sistem'));
        endif;
    }
	

}

?>